package com.imesne.assistant.jdbc.persist;

import com.imesne.assistant.jdbc.command.CommandContext;
import com.imesne.assistant.jdbc.exception.ImesneJdbcException;

/**
 * Created by liyd on 17/4/12.
 */
public abstract class AbstractPersistExecutor implements PersistExecutor {

    public Object execute(CommandContext commandContext) {

        if (commandContext.getCommandType() == CommandContext.CommandType.INSERT) {
            return this.insert(commandContext);
        } else if (commandContext.getCommandType() == CommandContext.CommandType.SELECT_OBJECT) {
            return this.selectObject(commandContext);
        } else if (commandContext.getCommandType() == CommandContext.CommandType.SELECT_OBJECT_LIST) {
            return this.selectObjectList(commandContext);
        } else if (commandContext.getCommandType() == CommandContext.CommandType.SELECT_LIST) {
            return this.selectList(commandContext);
        } else if (commandContext.getCommandType() == CommandContext.CommandType.SELECT_SINGLE) {
            return this.selectSingle(commandContext);
        } else if (commandContext.getCommandType() == CommandContext.CommandType.UPDATE) {
            return this.update(commandContext);
        } else if (commandContext.getCommandType() == CommandContext.CommandType.DELETE) {
            return this.delete(commandContext);
        } else {
            throw new ImesneJdbcException("不支持的执行类型");
        }
    }


    public abstract Object insert(CommandContext commandContext);

    public abstract Object selectObject(CommandContext commandContext);

    public abstract Object selectObjectList(CommandContext commandContext);

    public abstract Object selectList(CommandContext commandContext);

    public abstract Object selectSingle(CommandContext commandContext);

    public abstract Object update(CommandContext commandContext);

    public abstract Object delete(CommandContext commandContext);
}
